#light
#nowarn "40"

let memoize (f: 'a -> 'b) =
    let t = new System.Collections.Generic.Dictionary<'a,'b>()
    fun n ->
        if t.ContainsKey(n) then t.[n]
        else
            let res = f n
            t.Add(n,res)
            res
        
let rec fib =
    print_endline "fib executed"
    memoize (fun n -> print_endline "computed function executed"; if n <= 2 then 1 else fib(n-1) + fib(n-2))

printfn "%d" (fib 10)
printfn "%d" (fib 15)
printfn "%d" (fib 20)
printfn "%d" (fib 30)